package com.kws.commercial.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kws.commercial.dao.CommercialProjectDeviceManagement;
import com.kws.commercial.dao.Rq.CreateProjectScheduleRq;
import com.kws.commercial.mapper.CommercialProjectDeviceMapper;
import com.kws.commercial.service.CommercialProjectDeviceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <b>CommercialProjectDeviceServiceImpl</b>
 *
 * @description: CommercialProjectDeviceServiceImpl <br>
 * @date: 2024/10/29 15:33 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class CommercialProjectDeviceServiceImpl extends ServiceImpl<CommercialProjectDeviceMapper, CommercialProjectDeviceManagement> implements CommercialProjectDeviceService {
    private static final Logger logger = LoggerFactory.getLogger(CommercialProjectDeviceServiceImpl.class);


    @Override
    public boolean createProjectDevice(CreateProjectScheduleRq rq) {
        if (CollectionUtil.isNotEmpty(rq.getDeviceIds())){
            List<CommercialProjectDeviceManagement> saveList = new ArrayList<>();
            rq.getDeviceIds().forEach(item -> {
                CommercialProjectDeviceManagement commercialProjectDeviceManagement = new CommercialProjectDeviceManagement();
                commercialProjectDeviceManagement.setProjectQuotationId(rq.getProjectQuotationId());
                commercialProjectDeviceManagement.setDeviceId(item);
                saveList.add(commercialProjectDeviceManagement);
            });
            boolean b = this.saveBatch(saveList);
            return b;
        }
        return false;
    }
}
